﻿using DimOS.Internals;

namespace DimOS.DimFS
{
    public class Permissions
    {
        public Account Owner { get; set; } //Owner of the particular node (either User or Root)

        public bool Read { get; set; }   //Permission that allows reading the node's contents

        public bool Write { get; set; }  //Permission which allows writing to node's contents

        public bool Change { get; set; } //Permission which allows changing node's properties

        public bool Delete { get; set; } //Permission that allows deleting or moving the node

        public Permissions(Account owner, bool read, bool write, bool change, bool delete)
        {
            Owner = owner;
            Read = read;
            Write = write;
            Change = change;
            Delete = delete;
        }

        public static Permissions Default(Account owner)
        {
            if (owner == Account.Root) { return new Permissions(owner, true, false, false, false); }
            if (owner == Account.User) { return new Permissions(owner, true, true, true, true); }
            return null;
        }

        public static bool Compare(Permissions required, Permissions target)
        {
            if (required.Owner == Account.Root) return true;

            if ((required.Read && !target.Read) || (required.Write && !target.Write) ||
                (required.Change && !target.Change) || (required.Delete && !target.Delete))
                return false;
            return true;
        }
    }
}
